﻿/* Write a program that creates an array containing all letters from the alphabet (A-Z). 
 * Read a word from the console and print the index of each of its letters in the array.
 */



using System;
using System.Text.RegularExpressions;

class Alphabet
{
    static void Main()
    {
        char[] alphabet = { 'a', 'b', 'c', 
                            'd', 'e', 'f', 
                            'g', 'h', 'i', 
                            'j', 'k', 'l', 
                            'm', 'n', 'o', 
                            'p', 'q', 'r', 
                            's', 't', 'u', 
                            'v', 'w', 'x', 
                            'y', 'z'};
        bool iProvided = false;
        string w = null;

        //check for proper input and assign
        do
        {
            if (iProvided == true) Console.WriteLine("Error!: only letters are allowed (a-z, A-Z): ");
            else iProvided = true;
            Console.Write("Enter a word: ");
            w = Console.ReadLine().ToLower(); //parse to lower-cased string
        } while (!Regex.IsMatch(w, @"^[a-zA-Z]+$"));

        //convert the string we got to a char array
        char[] wcharArr = w.ToCharArray();

        //compare and output
        for (int i = 0; i < wcharArr.Length; i++)
        {
            for (int i_inner = 0; i_inner < alphabet.Length; i_inner++)
                if (alphabet[i_inner] == wcharArr[i]) Console.WriteLine("{0, -2} {1}", i_inner, alphabet[i_inner]);
        }
        //Console.WriteLine(w);

    }
}
